package Offer;

import java.util.Stack;

/**
 * 栈的压入、弹出序列
 * @author 是阿秋啊
 * @date 2022/08/17 17:01
 **/
public class Num31 {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> stack = new Stack<>();
        int i = 0;
        for(int num : pushed){
            stack.push(num);
            while(!stack.isEmpty() && stack.peek() == popped[i]){
                stack.pop();
                i++;
            }
        }
        return stack.isEmpty();
    }
}